<?php
if($_SESSION['ma_pq']=='trungtam'){
    header('Location: index.php?muc=daotao&modul=lichhoc_donvi');
}


include ("../lib/BLL/DonViBLL.php");
include ("../lib/BLL/DmNganhBLL.php");
include ("../lib/BLL/DonViHocVuBLL.php");
include ("../lib/BLL/DmMonHocBLL.php");
include ("../lib/BLL/DmCaHocBLL.php");
include ("../lib/BLL/KhoaHocBLL.php");
include ("../lib/BLL/LopMonBLL.php");
include ("../lib/BLL/CanBoBLL.php");
include ("../lib/BLL/QuaTrinhLopMonBLL.php");

$donvi=new DonViBLL();
$nganh=new DmNganhBLL();
$dvhv=new DonViHocVuBLL();
$monhoc= new DmMonHocBLL();
$cahoc= new DmCaHocBLL();
$khoahoc= new KhoaHocBLL();
$canbo= new CanBoBLL();
$lopmonBLL=new LopMonBLL();
$quatrinhlopmonBLL=new QuaTrinhLopMonBLL();
$lopmonDAL=new LopMon();
$quatrinhlopmonDAL=new QuaTrinhLopMon();
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$lich=null;
$nganh_lopmon=null;
$lich_thi1=$lich_thi2=$lich_thi=null;

$sql=  "SELECT  ten_lop,tbl_lop.ma_donvi FROM tbl_sv_lop,tbl_nhaphoc,tbl_lop 
        WHERE   tbl_sv_lop.ma_nhaphoc=tbl_nhaphoc.ma_nhaphoc 
        AND     tbl_sv_lop.ma_lop = tbl_lop.ma_lop
        AND     ma_sv='".$_SESSION['ma_cb']."'";         
$kq=mysql_fetch_array(mysql_query($sql));


if(isset($_POST['xem'])){
    $madonvi=$kq['ma_donvi'];
    $madvhv=$_POST['dvhv'];
    $makhoahoc=$_POST['khoahoc'];
}else{
    $madonvi=$kq['ma_donvi'];
    $madvhv='1-2013';
    $makhoahoc='2013';
}    
    $sqllich="SELECT  DISTINCT  tbl_lopmon.*,ten_mh,khungthoigian,khoiluong
                    FROM  tbl_ctdt,tbl_mon_ctdt,dm_monhoc,tbl_lopmon_monctdt,tbl_lopmon,dm_cahoc,tbl_dangkymon 
                    WHERE tbl_ctdt.ma_ctdt=tbl_mon_ctdt.ma_ctdt
                    AND   tbl_mon_ctdt.ma_monhoc=dm_monhoc.madm_mh
                    AND   tbl_dangkymon.ma_lopmon=tbl_lopmon.ma_lopmon
                    AND   tbl_mon_ctdt.ma_mon_ctdt=tbl_lopmon_monctdt.ma_mon_ctdt
                    AND   tbl_lopmon.ma_lopmon = tbl_lopmon_monctdt.ma_lopmon
                    AND   tbl_lopmon.madm_ca = dm_cahoc.madm_ca
                    AND   ma_donvi='$madonvi'
                    AND   ma_donvihocvu='$madvhv'
                    AND   ma_sv='".$_SESSION['ma_cb']."'";
             
    $ds_lopmon_sv=null;
    $kq=mysql_query($sqllich);
    while($row = mysql_fetch_array($kq)){
            $lich[] = $row;
            $ds_lopmon_sv.="'".$row['ma_lopmon']."',";
        }
    
    $ds_lopmon_sv=rtrim($ds_lopmon_sv,',');
    
    $ex_lichthi=mysql_query("   SELECT  * 
                                FROM    tbl_chitiet_lopmon 
                                WHERE   ma_lopmon IN ($ds_lopmon_sv)
                                AND     madm_ttctlm='thilan1'
                                ORDER BY madm_ttctlm");
    while($row = mysql_fetch_array($ex_lichthi)){
            $lich_thi1[] = $row;
        }  
    $ex_lichthi=mysql_query("   SELECT  * 
                                FROM    tbl_chitiet_lopmon 
                                WHERE   ma_lopmon IN ($ds_lopmon_sv)
                                AND     madm_ttctlm='thilan2'
                                ORDER BY madm_ttctlm");
    while($row = mysql_fetch_array($ex_lichthi)){
            $lich_thi2[] = $row;
        }  
    
    $nganh_lopmon=$lopmonBLL->getnganh_lopmon($madonvi,$madvhv);                


$smarty->assign('lich',$lich);
$smarty->assign('nganh_lopmon',$nganh_lopmon);
$smarty->assign('lich_thi1',$lich_thi1);
$smarty->assign('lich_thi2',$lich_thi2);
$smarty->assign('soluonglopmon',count($lich));
$smarty->assign('tenlop',$kq['ten_lop']);

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

$ds_donvi=$donvi->getListDonVi_Lienket();
$smarty->assign('ds_donvi',$ds_donvi);

$ds_dvhv= $dvhv->getListDonViHocVu();
$smarty->assign('ds_dvhv',$ds_dvhv);

$ds_cahoc=$cahoc->getListDmCaHoc();
$smarty->assign('ds_cahoc',$ds_cahoc);

$ds_namkhoahoc=$khoahoc->getListNamKhoaHoc();
$smarty->assign('ds_namkhoahoc',$ds_namkhoahoc);

$ds_canbo=$canbo->getListCanBo();
$smarty->assign('ds_canbo',$ds_canbo);


$smarty->display('daotao/xemlichhoc.tpl');   
?>